<template>
  <a-card :bordered="false" :loading="cardLoading">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="10">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="请选择时间">
              <g-year-picker
                placeholder="请选择时间"
                :is-init="false"
                v-model="queryParam.date"
              ></g-year-picker>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)" v-has="'user:classtime-operate'">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)" v-has="'user:classtime-operate'">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <classtime-report-modal ref="modalForm" @ok="modalFormOk"></classtime-report-modal>

  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ClasstimeReportModal from './modules/ClasstimeReportModal'
  import { getAction } from '@api/manage'
  import moment from 'moment'
  import Vue from 'vue'
  import { CURRENT_DATE } from '@/store/mutation-types'
  import GYearPicker from '@views/gfxy/common/GYearPicker'
  export default {
    name: 'classtimeReport',
    mixins:[JeecgListMixin],
    components: {
      ClasstimeReportModal,GYearPicker
    },
    props: ['value'],
    data () {
      return {
        description: '课时统计表管理页面',
        disableMixinCreated:true,
        dataopen: false,
        cardLoading: false,
        queryParam:{
          date: ''
        },
        // 表头
        columns: [
          {
            title:'时间',
            align:"center",
            dataIndex: 'date'
          },
          {
            title:'月份',
            align:"center",
            dataIndex: 'month'
          },
          {
            title:'教师',
            align:"center",
            dataIndex: 'teacherCode_dictText'
          },
          {
            title:'理论课',
            align:"center",
            dataIndex: 'lecture'
          },
          {
            title:'课程设计',
            align:"center",
            dataIndex: 'courseDesign'
          },
          {
            title:'实践课',
            align:"center",
            dataIndex: 'practical'
          },
          {
            title:'毕设指导',
            align:"center",
            dataIndex: 'graduateTutorial'
          },
          {
            title:'毕设答辩',
            align:"center",
            dataIndex: 'graduateDefense'
          },
          {
            title:'考试',
            align:"center",
            dataIndex: 'examination'
          },
          {
            title:'顶岗实习',
            align:"center",
            dataIndex: 'internship'
          },
          {
            title:'实践讲课',
            align:"center",
            dataIndex: 'practicalTutorial'
          },
          {
            title:'其他',
            align:"center",
            dataIndex: 'other'
          },
          {
            title:'总课时',
            align:"center",
            dataIndex: 'totalClasstime'
          }
          // ,
          // {
          //   title: '操作',
          //   dataIndex: 'action',
          //   align:"center",
          //   fixed:"right",
          //   width:147,
          //   scopedSlots: { customRender: 'action' }
          // }
        ],
        url: {
          list: "/classtime/classtimeReport/list",
          delete: "/classtime/classtimeReport/delete",
          deleteBatch: "/classtime/classtimeReport/deleteBatch",
          exportXlsUrl: "/classtime/classtimeReport/exportXls",
          importExcelUrl: "classtime/classtimeReport/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
      this.getSuperFieldList();
      this.queryParam.date = Vue.ls.get(CURRENT_DATE);
    },
    watch: {
      value: {
        immediate: true,
        handler(obj) {
          this.dataSource = []
          console.log("teacherCode:")
          console.log(obj)
          if(obj.isLeaf){
            console.log("查询")
            this.queryParam.teacherCode = obj.id;
            this.loadData()
          }

        }
      },
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'year',text:'时间',dictCode:''})
        fieldList.push({type:'string',value:'month',text:'月份',dictCode:''})
        this.superFieldList = fieldList
      },
      // loadData(pageNum, teacherCode){
      //   this.loading = true
      //   if (pageNum === 1) {
      //     this.ipagination.current = 1
      //   }
      //   getAction(this.url.list, {
      //     teacherCode,
      //     ...this.getQueryParams()
      //   }).then((res) => {
      //     console.log(res.result)
      //     if (res.success) {
      //       this.dataSource = res.result.records
      //       this.ipagination.total = res.result.total
      //     }
      //   }).finally(() => {
      //     this.loading = false
      //     this.cardLoading = false
      //   })
      // },
      openChangeYear: function(status) {
        if (status) {
          this.dataopen = true;
        } else {
          this.dataopen = false;
        }
      },
      panelChangeYear: function(value){
        const endOfYear = moment().endOf('year')
        if(value.endOf('year')>endOfYear){
          // alert("所选时间不能超过当前时间");
          this.errorModal('时间选择错误','所选时间不能超过当前时间');
        } else {
          this.queryParam.date = value.format('YYYY');
        }
        this.dataopen = false;
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>